Imports Microsoft.VisualBasic
Imports System.Text
Imports System.Data.SqlClient
Imports SQLtoASPX.Support

Public Class DetailASPX

    Private TableGen As RawCreateScript
    'Private mDatabaseName As String

    Public Sub New(ByVal TableGen As RawCreateScript)
        Me.TableGen = TableGen
    End Sub

    Public Overrides Function ToString() As String
        Dim sb As New StringBuilder

        Dim Spaces As New Space()
        Dim Extension As String = ""
        Select Case TableGen.CodeType
            Case CodeTypeEnum.VB2005
                Extension = "vb"
            Case CodeTypeEnum.CS2005
                Extension = "cs"
        End Select

        Select Case TableGen.CodeType
            Case CodeTypeEnum.VB2005
                sb.AppendLine("<%@ Page Language=""VB"" AutoEventWireup=""false"" CodeFile=""Edit" & TableGen.OutputFileName & ".aspx.vb"" Inherits=""Edit" & TableGen.ClassName & """ %>")
            Case CodeTypeEnum.CS2005
                sb.AppendLine("<%@ Page Language=""C#"" AutoEventWireup=""true"" CodeFile=""Edit" & TableGen.OutputFileName & ".aspx.cs"" Inherits=""Edit" & TableGen.ClassName & """ %>")
        End Select

        sb.AppendLine("<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">")

        sb.AppendLine("<html xmlns=""http://www.w3.org/1999/xhtml"" >")
        Spaces.Inc()
        sb.AppendLine(Spaces.ToString & "<head runat=""server"">")
        Spaces.Inc()
        sb.AppendLine(Spaces.ToString & "<title>")
        Spaces.Inc()
        sb.AppendLine(Spaces.ToString & "Edit" & TableGen.TableName)
        Spaces.Dec()
        sb.AppendLine(Spaces.ToString & "</title>")

        sb.AppendLine(Spaces.ToString & "<link href=""PCGStyleSheet.css"" rel=""stylesheet"" type=""text/css"" />")
        sb.AppendLine(Spaces.ToString & "<link id=""ThemesCSS"" runat=""server"" type=""text/css"" rel=""stylesheet"" />")

        sb.AppendLine(Spaces.ToString & "<script src=""http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"" type=""text/javascript""></script>")
        sb.AppendLine(Spaces.ToString & "<script src=""http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js"" type=""text/javascript""></script>")
        'sb.AppendLine(Spaces.ToString & "<script src=""jquery.ui.core.js"" type=""text/javascript""></script>")
        'sb.AppendLine(Spaces.ToString & "<script src=""jquery.ui.widget.js"" type=""text/javascript""></script>")
        sb.AppendLine(Spaces.ToString & "<script src=""jquery.ui.button.js"" type=""text/javascript""></script>")

        If TableGen.IsAnyColumnDateUsingDateTimePicker Then
            sb.AppendLine(Spaces.ToString & "<script src=""jquery.ui.datetimepicker.js"" type=""text/javascript""></script>")

        End If

        sb.AppendLine(Spaces.ToString & "<script type=""text/javascript"">")
        Spaces.Inc()
        sb.AppendLine(Spaces.ToString & "$(function() {")
        Spaces.Inc()
        sb.AppendLine(Spaces.ToString & "$('#cmdDelete').button();")
        sb.AppendLine(Spaces.ToString & "$('#cmdSave').button();")
        sb.AppendLine(Spaces.ToString & "$('#cmdCancel').button();")
        For Each Column As PCGColumn In TableGen.Columns
            If Column.IsDisplayColumn = True Then
                If Column.IsDate Then
                    If Column.DataFormat.ToUpper = "DATETIME" Then
                        JQueryDateTimeSection(sb, Column.ControlName, Spaces)
                    Else
                        JQueryDateSection(sb, Column.ControlName, Spaces)
                    End If
                End If
            End If
        Next

        Spaces.Dec()
        sb.AppendLine(Spaces.ToString & "});")
        Spaces.Dec()
        sb.AppendLine(Spaces.ToString & "</script>")
        Spaces.Dec()
        sb.AppendLine(Spaces.ToString & "</head>")
        sb.AppendLine(Spaces.ToString & "<body>")

        Spaces.Inc()
        sb.AppendLine(Spaces.ToString & "<form id=""form1"" runat=""server"">")

        Spaces.Inc()

        ASPXTableEdit(Spaces, sb, TableGen)

        Spaces.Dec()
        sb.AppendLine(Spaces.ToString & "</form>")
        Spaces.Dec()
        sb.AppendLine(Spaces.ToString & "</body>")
        Spaces.Dec()
        sb.AppendLine("</html>")

        Return sb.ToString
    End Function

End Class
